package com.project.lk.nurseapp.common.view.chat;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.lidong.photopicker.PhotoPagerAdapter;
import com.lidong.photopicker.widget.ViewPagerFixed;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.utils.AppManager;

import java.util.ArrayList;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class ShowImageActivity extends AppCompatActivity implements PhotoPagerAdapter.PhotoViewClickListener {


    @BindView(R.id.view_pager_photos)
    ViewPagerFixed mViewPager;
    private ArrayList<String> imageList;
    private PhotoPagerAdapter mPagerAdapter;
    private int position;
    private Map<Integer, String> mImageMap;
    private int pathIndex;

    private Unbinder mBind;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(getLayoutId());
        //设置全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
       getWindow().addFlags(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        AppManager.getAppManager().addActivity(this);
        //绑定黄油刀
        mBind = ButterKnife.bind(this);

        init();

    }

    private void init() {
        initData();
        initView();
    }

    protected void initData() {

        Intent intent = getIntent();
        position = intent.getIntExtra("position", 0);
        imageList = intent.getStringArrayListExtra("image");
        String path = intent.getStringExtra("path");

        for (int i=0;i<imageList.size();i++){

        }
        if (path!=null){
            if (imageList!=null){
                for (int i=0;i<imageList.size();i++){
                    if (TextUtils.equals(path,imageList.get(i))){

                        pathIndex= i;
                    }
                }
            }
        }else {
            pathIndex=position;
        }


    }

    protected void initView() {

        mPagerAdapter = new PhotoPagerAdapter(this, imageList);
        mPagerAdapter.setPhotoViewClickListener(this);
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setOffscreenPageLimit(9);
        //显示选中的图片
        mViewPager.setCurrentItem(pathIndex,false);
    }

    protected int getLayoutId() {
        return R.layout.activity_show_image;
    }


    @Override
    public void OnPhotoTapListener(View view, float v, float v1) {
        onBackPressed();
    }

    @Override
    public void onBackPressed() {
        AppManager.getAppManager().finishActivity();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mBind!=null){
            mBind.unbind();
        }
    }
}
